<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">
<head>
    <title>Title</title>
    <div th:replace="common/links::header"></div>
    <div th:replace="common/script::js_footer"></div>
    <link rel="stylesheet" th:href="@{/js/zTree_v3/css/metroStyle/metroStyle.css}" type="text/css">
    <script type="text/javascript" th:src="@{/js/jquery/jquery-3.3.1.min.js}"></script>
    <script th:src="@{/js/zTree_v3/js/jquery.ztree.all.js}"></script>
</head>
<body>
<div style="text-align: center;padding-bottom: 10%;">
    <ul id="menuTree" class="ztree"></ul>
    <hr class="layui-bg-gray">
    <button id="chooseBtn" type="button" shiro:hasPermission="sys:role:basic:br" class="layui-btn  layui-btn-sm" >确定</button>
    <button id="closeBtn" type="button" class="layui-btn layui-btn-primary  layui-btn-sm">取消</button>
</div>
<script th:inline="javascript">
    var setting = {
        check: {
            enable: true,
            chkStyle: "checkbox",
            radioType: "all"
        },
        view: {
            selectedMulti: true
        },
        data: {
            simpleData: {
                enable: true
            }
        }
    };
    var nodes = [[${menus}]];
    $(document).ready(function(){
        var zTreeObj = $.fn.zTree.init($("#menuTree"), setting, nodes);
        zTreeObj.expandAll(true);
        $("#chooseBtn").on('click',function(){
            var nodes = zTreeObj.getCheckedNodes(true);
            if (nodes.length === 0){
                layer.msg('请选中至少一个选项',{icon:5});
                return;
            }
            var ids = [];
            for (var i=0;i<nodes.length;i++){
                ids.push(nodes[i].id);
            }
            Common.ajaxFormSubmit(basePath + '/sys/role/bind-resource',{
                id:[[${id}]],
                resourceIds:ids
            },function (data) {
                layer.msg(data.msg,{icon:6},function () {
                    Common.closeFrame();
                });
            })
        })

        $("#closeBtn").on('click',function () {
            Common.closeFrame();
        })
    });
</script>
</body>
</html>